package com.jxc.dao.impl;

import java.io.FileInputStream;
import java.util.List;

import javax.annotation.Resource;

import net.sf.json.JSONObject;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.omg.CORBA.portable.InputStream;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.transaction.annotation.Transactional;

import com.jxc.dao.PagePowerDAO;

/**
 * @包名   com.jxc.imp
 * @文件名 PagePowerImpl.java
 * @作者   mopzyqing
 * @创建日期 Jul 23, 2010
 * @版本 V 1.0
 */
public class PagePowerImpl implements PagePowerDAO{
	
	public String getPower(List<Integer> roleList,String url,ApplicationContext ctx){
		String roleIdTj="";
		for(int i=0;i<roleList.size();i++){
			
			if(i==0){
				roleIdTj = "tbRole.roleId="+roleList.get(i);
			}else{
				roleIdTj = roleIdTj+" or tbRole.roleId="+roleList.get(i);
			}
		}
		SessionFactory sessionFactory = (SessionFactory)ctx.getBean("sessionFactory");
		Session session = sessionFactory.openSession(); 
		String queryString="select distinct tbPermission.opName from TbPermissionRole where tbPermission.tbMenu.menuParam='"+url+"' and ("+roleIdTj+")";
		Query queryObject = session.createQuery(
				queryString);
		 
	    List powerName = queryObject.list();
	    JSONObject jsonObject = new JSONObject();
	    for(int i=0;i<powerName.size();i++){
			jsonObject.put(powerName.get(i).toString(),true);
		}
	    session.close(); 
	    sessionFactory.close();
		return jsonObject.toString();
	}
}
